package spil;

import desktop_resources.GUI;

public abstract class Ownable extends Field {
	protected int price;
	protected Player owner;
	
	protected abstract int getRent();
	
	public Ownable(int fieldNumber, String title, String subText, String description) {
		super(fieldNumber, title, subText, description);
	}
	
	protected Ownable() {
		super();
	}
	
	public void buy(Player buyer) {
		if(buyer.getBalance() > price) {
			owner = buyer;
			buyer.account.withdraw(price);
			GUI.getUserButtonPressed(buyer + " bought " + title, "ok");
		}
		else GUI.getUserButtonPressed(buyer + " cannot afford " + title, "ok");
	}
	
	public void lose(Player p) {
		if(p.equals(owner))
			owner = null;
	}
	
	public Player getOwner() {
		return owner;
	}
}
